//研发环境配置
const path = require('path');
const copyPlugin = require('copy-webpack-plugin');
const htmlPlugin = require('html-webpack-plugin');
const fs = require('fs');

module.exports = {
	mode: 'development',
	//入口文件
	entry: './src/app.js',
	//出口
	output: {
		filename: 'app-[hash].js',
		path: path.resolve(__dirname, './dev/')
	},
	devServer: {
		contentBase: './dev',
		port: 9000,
		proxy: {
			'/api': {
				target: 'http://localhost:3000',
				pathRewrite: {
					'^/api': ''
				}
			}
		}
	},
	plugins: [
		new htmlPlugin({
			title: '拉勾后台管理系统',
			template: './src/index.html',
			filename: 'index.html'
		}),
		//文件的拷贝
		new copyPlugin([{
			from: './src/public/',
			to: './public/'
		}])
	],
	module: {
		rules: [{
			test: /\.html$/,
			use: [{
				loader: 'html-loader',
				options: {
					attrs: [':data-src']
				}
			}],
		}]
	}
}
